<?php
global $ress;
$ress = array(
	'article_color' => [1 => 'success', 2 => 'success', 3 => 'primary', 4 => 'primary', 5 => 'info', 6 => 'info', 7 => 'warning', 8 => 'warning'],
    'sex' => array(0 => '全部性别', 1 => '男性', 2 => '女性'),
    'mobile_match' => array(1 => '/^1[0-9]{10}$/'),
    'pm_red_state' => array(-1 => '红包退回', 0 => '未领取', 1 => '已发放', 9 => '已领取'),
    'pm_dashang_pay_state' => array(-1 => '退回', 0 => '未领取', 1 => '已发放', 9 => '已领取'),
    'goods_state' => array(0 => '新建商品',1 => '正常', DEL_STATUS => '删除'),
    'goods_cat_state' => array(1 => '正常', DEL_STATUS => '删除'),
    'order_state' => array(-1 => '付款失败', 0 => '新订单', 1 => '已付款', 3 => '已发货', 9 => '已完成', DEL_STATUS => '删除'),
    'order_state_search' => array(-1 => '付款失败', 0 => '新订单', 1 => '已付款', 3 => '已发货', 9 => '已完成', DEL_STATUS => '删除', 100 => '全部订单'),
    'notify_url' => array(
        1 => 'https://bq.pingzanwo.com/notify/user_payment',
        2 => 'https://bq.pingzanwo.com/notify/article',
        3 => 'https://bq.pingzanwo.com/notify/goods',
        4 => 'https://bq.pingzanwo.com/notify/znl',
    ),
    //吃喝标签
    'tid' => [
        1 => '公众号', 2 => 'CSDN', 3 => '简书', 4 => '掘金', 5 => '博客园'
    ],
    'x_cid' => [
        8 => '学习', 9 => 'web编程', 10 => '代码', 11 => '框架', 12 => '项目'
    ],
);

function resource_list($t, $dev = '') {
    global $ress;
    return isset($ress[$t]) ? $ress[$t] : $dev;
}

function resource($t, $status, $field = 'status', $dev = '-') {
    global $ress;
    $status = getid($status, $field);
    return isset($ress[$t][$status]) ? $ress[$t][$status] : $dev;
}

function resource_select($t, $name = 'status', $dev = '', $id = '', $class = '') {
    global $ress;
    $ret = '';
    if (isset($ress[$t])) {
        $ret = '<select name="' . $name . '" id="' . $id . '" class="' . $class . '">';
        foreach ($ress[$t] as $k => $v) {
            $ret .= '<option value="' . $k . '" ' . ($k == $dev ? 'selected="selected"' : '') . ' >' . $v . '</option>';
        }
        $ret .= '</select>';
    }
    return $ret;
}

function resource_radio($t, $name = 'status', $dev = '') {
    global $ress;
    $ret = '';
    if (isset($ress[$t])) {
        foreach ($ress[$t] as $k => $v) {
            $ret .= '<input type="radio" id="'.$name.$k.'" name="' . $name . '" value="' . $k . '" ' . ($k == $dev ? 'checked="checked"' : '') . ' />' . '<label style="margin:0 8px 0 4px;" for="'.$name.$k.'">'.$v.'</label>';
        }
    }
    return $ret;
}

function resource_key($type, $val, $defval = 0) {
    $ret = $defval;
    $list = resource_list($type, array());
    foreach ($list as $k => $v) {
        if ($v == $val) {
            $ret = $k;
            break;
        }
    }
    return $ret;
}
function resource_list_v($type, $val, $defval = 0) {
    $ret = $defval;
    $list = resource_list($type, array());
    foreach ($list as $k => $v) {
        if ($k == $val) {
            $ret = $v;
            break;
        }
    }
    return $ret;
}
function resource_set($t, $v) {
	global $ress;
	return $ress[$t] = $v;
}
function getid($o, $field = 'id') {
    return is_array($o) ? $o[$field] : $o;
}














